package com.adcc.loadsheet.billing.validator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;
import org.springframework.validation.beanvalidation.SpringValidatorAdapter;

import javax.validation.ValidatorFactory;

/**
 * Created by zhaoml on 2020/4/7.
 */
@Service
public class ValidationService {
    private SpringValidatorAdapter springValidatorAdapter;

    @Autowired
    ValidationService(ValidatorFactory validatorFactory) {
        this.springValidatorAdapter = new SpringValidatorAdapter(validatorFactory.getValidator());
    }

    public void validate(Object target, Errors errors) {
        springValidatorAdapter.validate(target, errors);
    }
}